package Buildings;
import Interfaces.*;
import Errors.*;
public class PlacementExchanger {
    public static boolean canWeExchangeSpace(Space s1,Space s2)throws InexchangeableSpacesException {
        boolean answer=false;
        if(s1.getHowMuchArea()==s2.getHowMuchArea() && s1.getHowMuchRooms()==s2.getHowMuchRooms()){
            answer=true;
        }
        return answer;
    }
    public static boolean canWeExchangeFloor(Floor f1,Floor f2)throws InexchangeableFloorsException{
        boolean answer=false;
        if(f1.getHowMuchAreaInFloor()==f2.getHowMuchAreaInFloor() && f1.getHowMuchSpaceInFloor()==f2.getHowMuchSpaceInFloor()){
            answer=true;
        }
        return answer;
    }
    public static void exchangeFloorRooms(Floor f1,int index1,Floor f2, int index2){
        try{
        if(canWeExchangeSpace(f1.getSpaceInFloor(index1),f2.getSpaceInFloor(index2))==true){
            Space buf,ubf;
            buf=f1.getSpaceInFloor(index1); //или создавать новый? т.к. это вроде просто ссылка
            ubf=f2.getSpaceInFloor(index2);
            f1.setSpaceInFloor(index1, ubf);
            f2.setSpaceInFloor(index2, buf);
        }else throw new InexchangeableSpacesException();
        }catch(InexchangeableSpacesException e){
            System.out.println(e);
        }
    }
    public static void exchangeBuildingFloors(Building b1,int index1,Building b2,int index2){
        try{
        if(canWeExchangeFloor(b1.getFloor(index1),b2.getFloor(index2))==true){
            Floor buf;
            buf=b1.getFloor(index1); //или создавать новый? т.к. это вроде просто ссылка
            b1.setFloor(index1, b2.getFloor(index2));
            b1.setFloor(index1, buf);
        }else throw new InexchangeableFloorsException();
        }catch(InexchangeableFloorsException e){
            System.out.println(e);
        }
    }
}
